package com.ruoyi.web.controller.jypc;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jypc.domain.Servicetype;
import com.ruoyi.jypc.service.IServicetypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修类别Controller
 * 
 * @author LYK
 * @date 2022-10-30
 */
@RestController
@RequestMapping("/jypc/servicetype")
public class ServicetypeController extends BaseController
{
    @Autowired
    private IServicetypeService servicetypeService;

    /**
     * 查询维修类别列表
     */
    @PreAuthorize("@ss.hasPermi('jypc:servicetype:list')")
    @GetMapping("/list")
    public TableDataInfo list(Servicetype servicetype)
    {
        startPage();
        List<Servicetype> list = servicetypeService.selectServicetypeList(servicetype);
        return getDataTable(list);
    }
    
    /**
     * 查询维修类别列表
     */
    @PreAuthorize("@ss.hasPermi('jypc:servicetype:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll() 
    {
        
        List<Servicetype> list = servicetypeService.selectServicetypeListAll();
        return getDataTable(list);
    }

    /**
     * 导出维修类别列表
     */
    @PreAuthorize("@ss.hasPermi('jypc:servicetype:export')")
    @Log(title = "维修类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Servicetype servicetype)
    {
        List<Servicetype> list = servicetypeService.selectServicetypeList(servicetype);
        ExcelUtil<Servicetype> util = new ExcelUtil<Servicetype>(Servicetype.class);
        util.exportExcel(response, list, "维修类别数据");
    }

    /**
     * 获取维修类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('jypc:servicetype:query')")
    @GetMapping(value = "/{typeid}")
    public AjaxResult getInfo(@PathVariable("typeid") Long typeid)
    {
        return AjaxResult.success(servicetypeService.selectServicetypeByTypeid(typeid));
    }

    /**
     * 新增维修类别
     */
    @PreAuthorize("@ss.hasPermi('jypc:servicetype:add')")
    @Log(title = "维修类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Servicetype servicetype)
    {
        return toAjax(servicetypeService.insertServicetype(servicetype));
    }

    /**
     * 修改维修类别
     */
    @PreAuthorize("@ss.hasPermi('jypc:servicetype:edit')")
    @Log(title = "维修类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Servicetype servicetype)
    {
        return toAjax(servicetypeService.updateServicetype(servicetype));
    }

    /**
     * 删除维修类别
     */
    @PreAuthorize("@ss.hasPermi('jypc:servicetype:remove')")
    @Log(title = "维修类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeids}")
    public AjaxResult remove(@PathVariable Long[] typeids)
    {
        return toAjax(servicetypeService.deleteServicetypeByTypeids(typeids));
    }
}
